package com.hqd.ch03.v23.utils;

import com.hqd.ch03.v23.registry.BeanDefinitionRegistry;

public class BeanDefinitionReaderUtils {
    public static final String GENERATED_BEAN_NAME_SEPARATOR = "#";

    /**
     * 生成bean名称
     *
     * @param beanName
     * @param registry
     * @return
     */
    public static String generateBeanName(String beanName, BeanDefinitionRegistry registry) {
        String id = beanName;
        int counter = -1;

        String prefix = beanName + GENERATED_BEAN_NAME_SEPARATOR;
        while (counter == -1 || registry.containsBeanDefinition(id)) {
            counter++;
            id = prefix + counter;
        }
        return id;
    }
}
